/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frameHist.java
 *
 * Created on Jan 11, 2010, 8:05:31 PM
 */

package gcs.Interface;

import gcs.Negocio.Historico;
import gcs.Negocio.Cliente;
import java.awt.Component;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Emanuel
 */
public class frameHist extends javax.swing.JFrame {

    Component [] com;
    Component [] com1;
    GCSView gcsv;

    /** Creates new form frameHist */
    public frameHist(Cliente c,Component[] x,Component[] x1,GCSView g) {
        initComponents();
        this.setTitle(c.getNome());
        refreshtable(c);

        com = x;
        com1=x1;
        gcsv=g;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTablehist = new javax.swing.JTable();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTablehist.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTablehist.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTablehist.setName("jTablehist"); // NOI18N
        jScrollPane1.setViewportView(jTablehist);

        fileMenu.setText("File");

        jMenuItem1.setText("Fechar histórico");
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem1);

        menuBar.add(fileMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        this.dispose();
        gcsv.EnableTrue();
        gcsv.EnableTrue2();
        gcsv.detalhes_tab2(false);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               // new frameHist().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTablehist;
    private javax.swing.JMenuBar menuBar;
    // End of variables declaration//GEN-END:variables


    public void refreshtable(Cliente c){


        String[] colunas = {"Codigo","Descricao"};
        DefaultTableModel model = new DefaultTableModel(null,colunas);
        jTablehist.setModel(model);

        
        for(int i=0;i<2;i++){
            TableColumn tabco = jTablehist.getColumnModel().getColumn(i);
            if(i==0)
                tabco.setPreferredWidth(70);
            if(i==1)
                tabco.setPreferredWidth(800);
        }

        DefaultTableModel dtm = (DefaultTableModel) jTablehist.getModel();
        for(Historico h : c.getHist()){
            dtm.addRow(new String[]{h.getCodHistorico(),h.getHist()});
        }
    }
}
